package com.zhongkun.datahome.web.rest;

import javax.annotation.Resource;

import com.zhongkun.datahome.common.core.domain.R;
import com.zhongkun.datahome.service.domain.Project;
import com.zhongkun.datahome.service.req.IdsBody;
import com.zhongkun.datahome.service.req.qry.project.ProjectQry;
import com.zhongkun.datahome.service.res.PageVo;
import com.zhongkun.datahome.service.res.project.ProjectVo;
import com.zhongkun.datahome.service.service.IProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhongkun.datahome.common.annotation.Log;
import com.zhongkun.datahome.common.core.controller.BaseController;
import com.zhongkun.datahome.common.enums.BusinessType;

/**
 * 项目Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@Api("项目管理")
@RestController
@RequestMapping("/core/project")
public class ProjectController extends BaseController {
    @Resource
    private IProjectService projectService;

    @ApiOperation("分页查询项目列表")
    @PreAuthorize("@ss.hasPermi('core:project:page')")
    @GetMapping("/page")
    public R<PageVo<ProjectVo>> page(ProjectQry qry) {
        return R.ok(projectService.page(qry));
    }

    @ApiOperation("获取项目详细信息")
    @PreAuthorize("@ss.hasPermi('core:project:query')")
    @GetMapping(value = "/{id}")
    public R<Project> getById(@PathVariable("id") Long id) {
        return R.ok(projectService.getById(id));
    }

    @ApiOperation("新增项目")
    @PreAuthorize("@ss.hasPermi('core:project:add')")
    @Log(title = "项目", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Long> add(@RequestBody Project project) {
        return R.ok(projectService.add(project));
    }

    @ApiOperation("修改项目")
    @PreAuthorize("@ss.hasPermi('core:project:edit')")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody Project project) {
        projectService.update(project);
        return R.ok();
    }

    @ApiOperation("删除项目")
    @PreAuthorize("@ss.hasPermi('core:project:remove')")
    @Log(title = "项目", businessType = BusinessType.DELETE)
	@DeleteMapping
    public R<Void> remove(@RequestBody IdsBody idsBody) {
        projectService.delete(idsBody.getIds());
        return R.ok();
    }
}
